//
//  JLPictureViewController.m
//  LIangeNews
//
//  Created by 孙金亮 on 16/2/11.
//  Copyright © 2016年 sun. All rights reserved.
//

#import "JLPictureViewController.h"
static NSString *  const ID = @"cell";
@interface JLPictureViewController ()<UITableViewDataSource,UITabBarDelegate,UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation JLPictureViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.leftBarButtonItem.target =self;
    self.navigationItem.leftBarButtonItem.action = @selector(leftItemClick);
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:ID];
}
-(void)leftItemClick{
    [self dismissViewControllerAnimated:YES completion:nil];
}
-(UIImageView *)iconImageView{
    if (_iconImageView.animationImages == nil) {
        NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:35];
        for (int i = 1; i < 35; i++) {
            [arrayM addObject:[UIImage imageNamed:[NSString stringWithFormat:@"bobo_flower_frame%02d.png",i]]];
        }
        _iconImageView.animationImages = arrayM;
    }
    return _iconImageView;
}
#pragma mark /***************tableView的数据源方法***************/
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 20;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell * cell = [self.tableView dequeueReusableCellWithIdentifier:ID forIndexPath:indexPath];
    cell.textLabel.text = [NSString stringWithFormat:@"%lu",indexPath.row];
    cell.backgroundColor = JLRandomColor;
    return cell;
    
}
#pragma mark /***************scrollView的数据源方法***************/
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    self.iconImageView.animationRepeatCount = 1;
    self.iconImageView.animationDuration = self.iconImageView.animationImages.count * 0.2;
    [self.iconImageView startAnimating];
    [UIView animateWithDuration:0.5 animations:^{
        self.tableView.transform = CGAffineTransformMakeTranslation(0, 80);
    }];
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    [UIView animateWithDuration:1 animations:^{
        self.tableView.transform = CGAffineTransformIdentity;
    }];
}
@end
